VERSION=''
re="\"(version)\": \"([^\"]*)\""

while read -r l; do
  if [[ $l =~ $re ]]; then
    value="${BASH_REMATCH[2]}"
    VERSION="$value"
  fi
done <package.json

# 项目名
NAME="stats"

# 拷贝dockerfile
cp -i ./deploy/Dockerfile ./

# 替换dockerfile版本号和名称
sed -i "s/v1.0.0/v${VERSION}/g;s/project/${NAME}/g" Dockerfile

# 镜像
docker image rm ${NAME}-frontend:v${VERSION}

docker image build --no-cache -t ${NAME}-frontend:v${VERSION} .

rm -f Dockerfile

# tag 为推送做准备
docker tag ${NAME}-frontend:v${VERSION} harbor.topvdn.com/develop_version/wsd/${NAME}-frontend:${VERSION}-alpine

# push

# docker login -u jinxiang -p LxXpFRs6Oc9xbqMd  https://harbor.topvdn.com/harbor/projects

#docker push harbor.topvdn.com/develop_version/wsd/${NAME}-frontend:${VERSION}-alpine
